<? include 'server_config.php'; 

if($_SESSION['user_idx'] == "")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}

if ($_POST['target_idx'] == "" || $_POST['target_idx'] == $user_idx)
{
	echo "-99";
	return;
}

$sql="
	SELECT COUNT(*) FROM ndd_friends WHERE user_idx=$user_idx AND friend_user_idx='".$_POST['target_idx']."';
";
$result = mysql_query($sql,$connect);
$row = mysql_fetch_row($result);

if($row[0]>0)
{
	echo "-1";
	return;
}
	

$sql="
	INSERT INTO ndd_friends VALUES (NULL, $user_idx, '".$_POST['target_idx']."');
";
$result = mysql_query($sql,$connect);

echo "0";
?>